<?php

namespace App\Http\Resources;

use Carbon\Carbon;
use Illuminate\Http\Resources\Json\JsonResource;

class NoteResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'id'=>$this->id,
            'title'=>$this->title,
            'pid'=>$this->pid,
            'type'=>$this->type_name,
            'note'=>$this->note,
            'ctime'=>Carbon::parse($this->ctime)->toDateTimeString(),
            'files'=>NoteFilesResource::collection($this->files),
        ];
    }
}
